package com.linhai.shoujiassitent.phoneinfo;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;

public class SoftWareLister {

	Context Xcontext;
	ArrayList<AppInfo> SysappList;
	ArrayList<AppInfo> UsrappList;
	ArrayList<AppInfo> AllappList;

	public SoftWareLister(Context context) {
		Xcontext = context;
	}

	/**
	 * 
	 * @return
	 */
	private ArrayList<AppInfo> listPackages() {
		AllappList = new ArrayList<AppInfo>();
		SysappList = new ArrayList<AppInfo>();
		UsrappList = new ArrayList<AppInfo>();
		List<PackageInfo> packages = Xcontext.getPackageManager()
				.getInstalledPackages(0);
		for (int i = 0; i < packages.size(); i++) {
			PackageInfo packageInfo = packages.get(i);
			AppInfo tmpInfo = new AppInfo();
			tmpInfo.appname = packageInfo.applicationInfo.loadLabel(
					Xcontext.getPackageManager()).toString();
			tmpInfo.packagename = packageInfo.packageName;
			tmpInfo.versionName = packageInfo.versionName;
			tmpInfo.versionCode = packageInfo.versionCode;
			tmpInfo.appicon = packageInfo.applicationInfo.loadIcon(Xcontext
					.getPackageManager());
			if ((packageInfo.applicationInfo.flags & packageInfo.applicationInfo.FLAG_SYSTEM) <= 0) {
				// customs applications
				UsrappList.add(tmpInfo);
			} else {
				SysappList.add(tmpInfo);
			}
			AllappList.add(tmpInfo);

		}

		return AllappList;
	}

}
